package com.loopy.servlet.servletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class OrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();
       /* Object visit_count = servletContext.getAttribute("visit_count");
        if(visit_count==null){
            servletContext.setAttribute("visit_count",1);
            visit_count=1;
        }else{
            visit_count=Integer.parseInt(visit_count+"")+1;
            servletContext.setAttribute("visit_count",visit_count);
        }*/
        Integer visit_count = WebUtils.visitCount(servletContext);
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.print("<h1>登录次数是"+visit_count+"</h1>");
    }
}
